package com.hsc.www.sentinel;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
public class HelloController {

    @RequestMapping("hello1")
    public String hello1(String id) throws Exception {
        String s = LocalDateTime.now().toString();
        System.out.println(s);
        return s;
    }

    @RequestMapping("hello2")
    @SentinelResource(value = "hello2", blockHandler = "blockHandlerFun", fallback = "fallbackFun")
    public String hello2(String id) throws Exception {
        String s = LocalDateTime.now().toString();
        System.out.println(s);
        return s;
    }


    @RequestMapping("hello3")
    @SentinelResource(value = "hello3", blockHandler = "blockHandlerFun", fallback = "fallbackFun")
    public String hello3(String id) throws Exception {
        System.out.println("dddddd");
        int i = 1 / 0;
        return null;
    }

    public String blockHandlerFun(String id, BlockException e) {
        System.out.println("blockHandlerFun " + e.getMessage());
        return "blockHandlerFun " + e.getMessage();
    }

    public String fallbackFun(String id, Throwable e) {
        System.out.println("fallbackFun :" + e.getMessage());
        return "fallbackFun :" + e.getMessage();
    }

}